<template>
	<view>
		<u-button type="primary" style="margin-top: 30px;" @click="getdata">打卡</u-button>
		<view class="" style="display: flex;justify-content: center;margin-top: 40px;">
			教师考勤时间
		</view>
		<view v-for="(item,index) in time" :key="index" style="width: 100%;height: 100px;background-color: silver;;margin-top: 20px;">
			<p>教师姓名:{{item.teacherName}}</p>
			<p>出勤时间:{{item.attendanceTime}}</p>
			<p>手机号:{{item.phonenumber}}</p>
			<p>在岗时长:{{item.dutyTime}}小时</p>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			attendanceTime:"",
			time:""
			}
		},
		methods: {
			gettimee(){
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/attendanceView/list', //获取教师考勤时间接口
					header: {
						'Authorization': uni.getStorageSync("token")
					},
					success: (res) => {
						if (res.statusCode == 200) {
							if (res.data.code == 200) {
								console.log(res.data.rows);
			                     this.time=res.data.rows
							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常,请联系管理员')
							}
						} else {
							uni.$u.toast('系统服务异常,请联系管理员')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('系统服务异常,请联系管理员')
					}
				});
			},
			getdata() {
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/attendanceView', //教师考勤接口
					method: 'POST',
					data:{
						attendanceTime:this.attendanceTimes
					},
					header: {
						'Authorization': uni.getStorageSync("token")
					},
					success: (res) => {
						if (res.statusCode == 200) {
							if (res.data.code == 200) {
								console.log(res);
									uni.$u.toast("打卡成功")
							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常,请联系管理员')
							}
						} else {
							uni.$u.toast('系统服务异常,请联系管理员')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('系统服务异常,请联系管理员')
					}
				});
			}

		},
		onLoad() {
			let old=new Date
			let nian=old.getFullYear()
			let yue=old.getMonth()+1
			let ri=old.getDate()
			let time=nian+'-'+yue+'-'+ri
			this.attendanceTime=time
			// console.log(this.attendanceTime);
			this.gettimee()
		}
	}
</script>

<style>

</style>